package com.colin.aiyi.adapter;


import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.colin.aiyi.R;
import com.colin.aiyi.app.Constant;
import com.colin.aiyi.entity.YiJuAndYiShuoEntity;
import com.colin.aiyi.utils.TimeUtil;

import java.util.List;


public class OneSayAdapter extends BaseQuickAdapter<YiJuAndYiShuoEntity, BaseViewHolder>{

    private Context context;


    public OneSayAdapter(List<YiJuAndYiShuoEntity> list, Context context) {
        super(R.layout.item_layout_img_right, list);
        this.context = context;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int positions) {
        super.onBindViewHolder(holder, positions);
    }

    @Override
    protected void convert(BaseViewHolder helper, YiJuAndYiShuoEntity item) {
        helper.addOnClickListener(R.id.text_like).addOnClickListener(R.id.img_video)
                .addOnClickListener(R.id.img_video_play)
                .addOnClickListener(R.id.text_watch)
                .addOnClickListener(R.id.text_reply);
        helper.setText(R.id.text_title, item.getTitle());
        helper.setText(R.id.text_decs, item.getContent());

        helper.getView(R.id.text_free).setVisibility(View.VISIBLE);
        if (item.isIsFree())
        {
            helper.getView(R.id.text_free).setVisibility(View.INVISIBLE);
        }

        ((TextView)helper.getView(R.id.text_watch)).getCompoundDrawables()[0].setLevel(0);
        if (item.getWatchCountActive()==1)
        {
            ((TextView)helper.getView(R.id.text_watch)).getCompoundDrawables()[0].setLevel(1);
        }

        ((TextView)helper.getView(R.id.text_like)).getCompoundDrawables()[0].setLevel(0);
        if (item.getLikeCountActive()==1)
        {
            ((TextView)helper.getView(R.id.text_like)).getCompoundDrawables()[0].setLevel(1);
        }
        helper.setText(R.id.text_watch,item.getWatchCount()+"");
        helper.setText(R.id.text_like,item.getLikeCount()+"");
        helper.setText(R.id.text_reply,item.getCommentCount()+"");
        helper.setText(R.id.text_date, TimeUtil.getTime(item.getUpdatedDate(),TimeUtil.DATE_FORMAT_DATE_1));
        ImageView imageView = helper.getView(R.id.img_video);
        Glide.with(imageView.getContext()).load(Constant.BASE_URL+item.getUrl()).error(R.mipmap.pic1).into(imageView);
    }




}
